package com.matrix.storage.controller;

import com.matrix.common.domain.Result;
import com.matrix.storage.service.StorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 有点甜
 * @since 2025/7/25
 */
@RestController
@RequestMapping("/storage")
@RequiredArgsConstructor
public class StorageController {

    private final StorageService storageService;

    @PostMapping("/upload/avatar")
    public Result<String> uploadAvatar(@RequestParam("file") MultipartFile file,
                                       @RequestHeader("X-User-ID") Long userId) {
        String url = storageService.uploadFile(file, userId, "avatar");
        return Result.success(url);
    }

    @PostMapping("/upload/review-image")
    public Result<String> uploadReviewImage(@RequestParam("file") MultipartFile file,
                                            @RequestHeader("X-User-ID") Long userId) {
        String url = storageService.uploadFile(file, userId, "review");
        return Result.success(url);
    }
}
